package JDBC;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import Model.Matiere;


public class Matiere_Ajouter {


	public void ajouter(Matiere mat) {

		try {	

			connexionBDD a = new connexionBDD();
			Connection conn=a.connect();

			Statement state = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

			Statement state1 = conn.createStatement();
			ResultSet result = state1.executeQuery("Select MAX(id_matiere) from matiere");
						
			int idm=0;
			
			try{
				while(result.next()){
					idm=Integer.parseInt(result.getObject(1).toString())+1;
				}
			}
			catch(Exception e){		
			}
			
			result.close();
			
			System.out.println("Creation matiere");
			state.executeUpdate("INSERT INTO matiere VALUES ("+idm+",'"+mat.matiere+"');");	
			System.out.println("Creation matiere reussie");
			state.close();
		} 

		catch (Exception e) {
			e.printStackTrace();
		}	

	}

}
